

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class PrimaryNums {
	private final static int MAX_NUMBER = 1024 * 256;

	public static List<Integer> primes = new ArrayList<>();

	public static void generatePrimes(int maxNumber) {
		boolean[] isPrime = new boolean[maxNumber + 1];

		Arrays.fill(isPrime, true);

		// mark non-primes <= N using Sieve of Eratosthenes
		for (int i = 2; i * i <= maxNumber; i++) {

			// if i is prime, then mark multiples of i as non-prime
			// suffices to consider multiples i, i+1, ..., N/i
			if (isPrime[i]) {
				for (int j = i; i * j <= maxNumber; j++) {
					isPrime[i * j] = false;
				}
			}
		}

		for (int number = 2; number <= maxNumber; number++) {
			if (isPrime[number]) {
				primes.add(number);
			}
		}
	}

	public static void main(String[] args) {
		generatePrimes(MAX_NUMBER);
		Factorizator f = new Factorizator(DKUtil.makeIntArray(primes));

		Timer t = new Timer();

		System.out.println("MAX_NUMBER: " + MAX_NUMBER);

		t.start();
		for (int i = 1; i <= 128; i++) {
			int number = 1024 * i - 1;
			int[] factors = f.expensiveFactorize(number);
			System.out.println(number + " -> " + Arrays.toString(factors));
		}
		System.out.println("Counter: " + f.getCount());
		t.printSeconds();
	}
}
